﻿using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Text;
using System.Windows;
using Fluent;
using PefStudio.Base;
using PefStudio.StartUp;

namespace PefStudio.Windows
{
    public class AbstractRibbonToolBar : RibbonToolBar, IRibbonToolBar, IPartImportsSatisfiedNotification
    {
        [Import(Bootstrapper.MainWindowContract, typeof(Window))]
        private Lazy<MainWindow> mainWindow { get; set; }
        protected MainWindow MainWindow
        {
            get { return mainWindow.Value; }
        }

        public string ID { get; set; }
        public double Index { get; set; }
        public string InsertRelativeToID { get; set; }
        public bool BeforeRelativeID { get; set; }

        protected string BaseContract{ get; set; }
        public virtual void OnImportsSatisfied()
        {
            try
            {
                var children =
                    MainWindow.CompositionContainer.GetExportedValues<IRibbonChildItem>(BaseContract);
                CreateService.CreateCollection(Children, children);
            }
            catch (ImportCardinalityMismatchException)
            {
            } 
            //try
            //{
            //    var layoutDefinitions =
            //        MainWindow.CompositionContainer.GetExportedValues<IRibbonToolBarLayoutDefinition>(
            //            BaseContract);
            //    CreateService.CreateCollection(LayoutDefinitions, layoutDefinitions);
            //}
            //catch (ImportCardinalityMismatchException)
            //{
            //}
        }
    }

    //public class AbstractRibbonToolBarLayoutDefinition : RibbonToolBarLayoutDefinition, IRibbonToolBarLayoutDefinition, IPartImportsSatisfiedNotification
    //{
    //    [Import(Bootstrapper.MainWindowContract, typeof(Window))]
    //    private Lazy<MainWindow> mainWindow { get; set; }
    //    protected MainWindow MainWindow
    //    {
    //        get { return mainWindow.Value; }
    //    }

    //    public string ID { get; set; }
    //    public double Index { get; set; }
    //    public string InsertRelativeToID { get; set; }
    //    public bool BeforeRelativeID { get; set; }

    //    protected string BaseContract { get; set; }
    //    public virtual void OnImportsSatisfied()
    //    {
    //        try
    //        {
    //            var rows =
    //                MainWindow.CompositionContainer.GetExportedValues<IRibbonToolBarRow>(
    //                    BaseContract);
    //            CreateService.CreateCollection(Rows, rows);
    //        }
    //        catch (ImportCardinalityMismatchException)
    //        {
    //        }
    //    }
    //}

    //public class AbstractRibbonToolBarRow : RibbonToolBarRow, IRibbonToolBarRow, IPartImportsSatisfiedNotification
    //{
    //    [Import(Bootstrapper.MainWindowContract, typeof(Window))]
    //    private Lazy<MainWindow> mainWindow { get; set; }
    //    protected MainWindow MainWindow
    //    {
    //        get { return mainWindow.Value; }
    //    }

    //    public string ID { get; set; }
    //    public double Index { get; set; }
    //    public string InsertRelativeToID { get; set; }
    //    public bool BeforeRelativeID { get; set; }

    //    protected string BaseContract { get; set; }
    //    public virtual void OnImportsSatisfied()
    //    {
    //        try
    //        {
    //            var children = MainWindow.CompositionContainer.GetExportedValues<IRibbonToolBarControlDefinition>(
    //                BaseContract);
    //            CreateService.CreateCollection(Children, children);
    //        }
    //        catch (ImportCardinalityMismatchException)
    //        {
    //        }
    //        try
    //        {
    //            var children = MainWindow.CompositionContainer.GetExportedValues<IRibbonToolBarControlGroupDefinition>(
    //                BaseContract);
    //            CreateService.CreateCollection(Children, children);
    //        }
    //        catch (ImportCardinalityMismatchException)
    //        {
    //        }
    //    }
    //}

    //public class AbstractRibbonToolBarControlDefinition : RibbonToolBarControlDefinition, IRibbonToolBarControlDefinition
    //{
    //    [Import(Bootstrapper.MainWindowContract, typeof(Window))]
    //    private Lazy<MainWindow> mainWindow { get; set; }
    //    protected MainWindow MainWindow
    //    {
    //        get { return mainWindow.Value; }
    //    }

    //    public string ID { get; set; }
    //    public double Index { get; set; }
    //    public string InsertRelativeToID { get; set; }
    //    public bool BeforeRelativeID { get; set; }
    //}

    //public class AbstractRibbonToolBarControlGroupDefinition : RibbonToolBarControlGroupDefinition, IRibbonToolBarControlGroupDefinition, IPartImportsSatisfiedNotification
    //{
    //    [Import(Bootstrapper.MainWindowContract, typeof(Window))]
    //    private Lazy<MainWindow> mainWindow { get; set; }
    //    protected MainWindow MainWindow
    //    {
    //        get { return mainWindow.Value; }
    //    }

    //    public string ID { get; set; }
    //    public double Index { get; set; }
    //    public string InsertRelativeToID { get; set; }
    //    public bool BeforeRelativeID { get; set; }

    //    protected string BaseContract { get; set; }
    //    public virtual void OnImportsSatisfied()
    //    {
    //        try
    //        {
    //            var children = MainWindow.CompositionContainer.GetExportedValues<IRibbonToolBarControlDefinition>(
    //                BaseContract);
    //            CreateService.CreateCollection(Children, children);
    //        }
    //        catch (ImportCardinalityMismatchException)
    //        {
    //        }
    //    }
    //}
}
